import java.util.Scanner;

public class Test {
    public static void main12(String[] args) {

    }

    public static int fbl2(int n){//用循环的方法求斐波那契数列的第n项
        if (n == 1||n == 2){
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 1;
        for (int i = 3; i <=n ; i++) {
            f3 = f1 + f2;//交换数字
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main(String[] args) {
        System.out.println(fbl2(3));
        System.out.println(fbl2(6));
        System.out.println(fbl2(30));

    }
    //递归求斐波那契数列的第n项
    public static int fbl(int n){
        if (n == 1){
            return 0;
        }
        else if (n == 2){
            return 1;
        }
        return fbl(n-2)+fbl(n-1);
    }
    public static void main10(String[] args) {
        System.out.println(fbl(5));
        System.out.println(fbl(6));
        System.out.println(fbl(30));

    }
    //递归实现各个数字的位数的数字和
    public static int sum1(int a){
        if (a < 10){
            return a;
        }
        return a%10+sum1(a/10);
    }
    public static void main9(String[] args) {
        System.out.println(sum1(123));
    }
    //递归实现1至n的数字和
    public static int sum(int n){
        if(n == 1){
            return 1;
        }
        return n + sum(n-1);
    }
    public static void main8(String[] args) {
        System.out.println(sum(10));


    }
    //递归计算数字的各个位数的数字
    public static void print(int n){
        if (n == 1){
            System.out.println(n%10);
            return;
        }
        print(n/10);
        System.out.println(n%10);
    }
    public static void main7(String[] args) {
        print(123);
    }
    public static int factor(int n){
        //简单的递归使用
        System.out.println("函数开始，n ="+n);
        if (n == 1){
            System.out.println("函数结束，n = 1 ret = 1");
            return 1;
        }
        int ret = n * factor(n-1);
        System.out.println("函数结束，n ="+n+"ret"+ret);
        return ret;
    }
    public static void main6(String[] args) {
        factor(4);

    }
    //递归小应用
    public static void func(int a){
        if(a == 1){
            return;
        }
        func(a-1);
    }
    public static void main5(String[] args) {
        func(10);
    }
    //定义方法实现n的阶乘和
    public static int f1(int i){
        //各个阶乘
        int tmp = 1;
        for (int j = 1; j <= i ; j++) {
            tmp *= j;

        }
        return tmp;
    }
    public static int f2(int n){
        //阶乘和
        int sum = 0;
        for (int i = 1; i <= n ; i++) {
            sum += f1(i);
        }
        return sum;
    }
    public static void main4(String[] args) {
        System.out.println(f2(4));


    }
    public static void main3(String[] args) {
        //基本方法实现计算N的阶乘
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int sum = 0;
        for (int i = 1; i <=n; i++) {
            int tmp = 1;
            for (int j = 1; j <= i; j++) {
                tmp *= j;
            }
            sum += tmp;
        }
        System.out.println(sum);
    }
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = 1;
        int i = 1;
        for (;i <= n;i=6) {
            m *=i;
            System.out.println(i);

        }
        System.out.println(i);
    }
    public static int max2(int a,int b){
         return a > b ? a:b;
    }
    public static int max3(int a,int b,int c){
         int ret = max2(a,b);
         return max2(ret,c);
    }
    public static void main1(String[] args) {
        //方法的使用
        System.out.println(max3(2,3,5));

    }
}
